459E - Pashmak and Graph - CodeForces Solution


dp sortings *1900

Please click on ads to support us..

C++ Code:

/// Template path: /home/mohammed/.config/sublime-text-3/Packages/User

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

// typedef
typedef long long ll;
typedef long double ld;
typedef vector<int> vecint;
typedef vector<char> vecchar;
typedef vector<string> vecstr;
typedef vector<long long> vecll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// Marcos
#define endl ("\n")
#define int long long
#define mod 1000000007
#define pi (3.141592653589)
#define REP(i,a,b) for (int i = a; i < b; i++)
#define RREP(i,a,b) for (int i = a; i > b; i--)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

// Functions
long long squared(long long x) {return (x * x) % mod;}
int factorial(int n) {long long res = 1; for (int i = 1; i <= n; i++) {res = ((res * i) % mod + mod) % mod ;} return res;}
long long power(long long x, long long p) {if (p == 0) {return 1;} if (p % 2 == 1) {return (power(x, p - 1) * x) % mod;} return squared(power(x, p / 2));}

// cout << fixed;
// cout << setprecision(4);


// ---------(^_^)--------- //




void main_solve() {


	int n, m; cin >> n >> m;


	vector<vector<int>> v;
	for (int i  = 0; i < m; i ++) {
		int u, w, m; cin >> u >> w >> m;
		v.push_back({m, u, w});
	}
	sort(v.begin(), v.end());
	int result = 1;
	vector<int> edg(n + 1);
	vector<vector<int>> o;
	for (int i = m - 1; i >= 0 ; i--) {
		if (i < m - 1 && v[i][0] != v[i + 1][0]) {
			for (auto &i : o) {
				edg[i[0]] = max(edg[i[0]], i[1]);
			}
			o.clear();
		}
		int e = 1;
		e = max(e, 1 + edg[v[i][2]]);
		result = max(result, e);
		o.push_back({v[i][1], e});

	}



	cout << result << endl;






}


int32_t main() {

	fast;
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	// Just another problem (-_-)

	int t;
	t = 1;
	// cin >> t;

	while (t--) {
		main_solve();
	}


}


Comments

Submit
0 Comments
More Questions

766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament